<?php
include '../class/class.detail.php';

if(isset($_REQUEST['aksi_rekam_detail'])){

	session_start();
	$id_user=$_SESSION['id_user'];
	$nip=$_POST['nip'];
	$id_usulan=$_POST['id_usulan'];
	$tgl_mulai=$_POST['tgl_mulai'];
	$tgl_selesai=$_POST['tgl_selesai'];
	$id_cuti=$_POST['id_cuti'];
	$id_tujuan=$_POST['id_tujuan'];
	$msg=false;
	$error='Gagal Simpan Pegawai';

	$detail=new Detail();

	$detail->id_usulan=$id_usulan;
	$detail->nip=$nip;
	$detail->tgl_mulai=$tgl_mulai;
	$detail->tgl_selesai=$tgl_selesai;
	$detail->id_cuti=$id_cuti;
	$detail->id_tujuan=$id_tujuan;
	$detail->id_user=$id_user;

	$detailDao=new DetailDao();

	$hasil=$detailDao->createDetail($detail);

	if($hasil){
		$msg=true;
	}

	$data=array(
		'msg' => $msg,
		'error' => $error,
		);

	echo json_encode($data);
}

if(isset($_REQUEST['aksi_get_det_peg'])){
    $id_det_usulan=$_REQUEST['id_usulan_peg'];
    $msg=false;
    
    $detailDao=new DetailDao();
    
    $hasil=$detailDao->getDetailById($id_det_usulan);

    
    echo json_encode($hasil);
}

if(isset($_REQUEST['aksi_simpan_ubah_peg'])){
    session_start();
    $id_user=$_SESSION['id_user'];
    $nip=$_POST['nip'];
    $id_det_usulan=$_POST['id_det_usulan'];
    $tgl_mulai=$_POST['tgl_mulai'];
    $tgl_selesai=$_POST['tgl_selesai'];
    $id_cuti=$_POST['id_cuti'];
    $id_tujuan=$_POST['id_tujuan'];
    $msg=false;
    $error='Gagal Simpan Pegawai';
    
    $detail=new Detail();

	$detail->id_detail=$id_det_usulan;
	$detail->nip=$nip;
	$detail->tgl_mulai=$tgl_mulai;
	$detail->tgl_selesai=$tgl_selesai;
	$detail->id_cuti=$id_cuti;
	$detail->id_tujuan=$id_tujuan;
	

	$detailDao=new DetailDao();

	$hasil=$detailDao->updateDetail($detail);

	if($hasil){
		$msg=true;
	}

	$data=array(
		'msg' => $msg,
		'error' => $error,
		);

	echo json_encode($data);
}

if(isset($_REQUEST['aksi_hapus_det'])){
    $id_det_usulan=$_REQUEST['id_det_usulan'];
    
    $detailDao=new DetailDao();
    $msg=false;    
    
    $detail=$detailDao->getDetailById($id_det_usulan);
    
    $id_usulan=$detail['id_usulan'];
    
    $hapus=$detailDao->deleteDetail($id_det_usulan);
    
    if($hapus){
        $msg=true;
    }
    
    $data=array(
        'msg' => $msg,
        'id_usulan' => $id_usulan,
    );
    
    echo json_encode($data);
}

?>